import os
from utils.common import dump_json,load_logging_config
import logging

def release_bttask():
    name='task3'
    typ='train' # 单选
    host='localhost'
    pcb='cpu'
    metrics=['train_duration'] # 多选 val_accuracy,cpu_utility,memory_usage,gpu_utility,gpu_memory_usage,gpu_memory_utility,gpu_temperature,gpu_power,gpu_clock_frequency,accuracy,latency,throughput
    audio_conversion=''
    model_save_dir='/home/tellw/saved_models'
    model_save_style='weights'
    train_stop_criterion={
        'category':'delta_loss',
        'threshold':1,
        'times':1
    }
    infer_stop_criterion={
        'category': 'data_num_epoch',
        'threshold': 1
    }
    infer_scenario_online={
        'category': 'online',
        'client_num':4,
        'request_interval_distribution':'uniform', # 'request_interval_distribution':'normal','request_interval_distribution_params':'0,1'; 'request_interval_distribution':'const','request_interval_distribution_params':'1';'request_interval_distribution':'poisson','request_interval_distribution_params':'' #持续地发请求 continuously;'request_interval_distribution':'real-time','request_interval_distribution_params':''
        'request_interval_distribution_params':'0.5,1'
    }
    infer_scenario_offline={
        'category': 'offline'
    }
    dataset='strongho_thchs30'
    summary_again=False
    maintain_data_style='total'
    fpfes=['fpfe1','no_behavior_']
    train_data_preprocessor='dp1'
    val_data_preprocessor='dp1_without_y'
    test_data_preprocessor='dp1_without_y'
    post_processor='ctc_decode_and_remove_tails'
    acoustic_model='SpeechModel251BN1Small'
    lexicon_dict='ld1'
    batch_size=8
    checkpoint_iters='10i'
    train_data_num=10 # 数据集的数据条目数量
    val_data_num=10
    test_data_num=10
    status='releasing'
    save_ckpt_interval=1
    hardware_cost_collection_interval=1
    executor='local_service'
    device_id=0
    lm='2gram'
    decoder='chinese_pinyin2word_2gram_dec'

    bttask_json={
        'name':name,
        'type':typ,
        'host':host,
        'pcb':pcb,
        'metrics':metrics,
        'audio_conversion':audio_conversion,
        'dataset':dataset,
        'summary_again':summary_again,
        'maintain_data_style':maintain_data_style,
        'fpfes':fpfes,
        'train_data_preprocessor':train_data_preprocessor,
        'val_data_preprocessor':val_data_preprocessor,
        'test_data_preprocessor':test_data_preprocessor,
        'acoustic_model':acoustic_model,
        'lexicon_dict':lexicon_dict,
        'batch_size':batch_size,
        'checkpoint_iters':checkpoint_iters,
        'train_data_num':train_data_num,
        'val_data_num':val_data_num,
        'test_data_num':test_data_num,
        'status':status,
        'save_ckpt_interval':save_ckpt_interval,
        'hardware_cost_collection_interval':hardware_cost_collection_interval,
        'executor':executor,
        'device_id':device_id,
        'post_processor':post_processor,
        'lm':lm,
        'decoder':decoder
    }
    if typ=='train':
        bttask_json['train']={
            'model_save_dir':model_save_dir,
            'train_stop_criterion':train_stop_criterion,
            'model_save_style':model_save_style
        }
    else:
        bttask_json['infer']={
            'infer_stop_criterion':infer_stop_criterion,
            'infer_scenarios':[infer_scenario_online,infer_scenario_offline]
        }
    
    if f'{name}.json' not in os.listdir('jsons/bttasks'):
        dump_json(bttask_json,f'jsons/bttasks/{name}.json')
    else:
        logging.error('基准测试任务重名，请重命名')


if __name__=='__main__':
    load_logging_config()
    release_bttask()